using System;

public class TokenResponse
{
    public string ErrorTrace { get; set; }
    public int? ErrorCode { get; set; }
    public string Prompt { get; set; }
    public bool Success { get; set; }
    public TokenData Data { get; set; }
}

public class TokenData
{
    public string AccessToken { get; set; }
    public int ExpiresIn { get; set; }
}

public class TokenService
{
    // 模拟的appkey和appsecret，实际使用时应从配置文件或安全存储中获取
    private static readonly string ValidAppKey = "IN2GvivxLR4nelc";
    private static readonly string ValidAppSecret = "ktFBu91tCtrVf3ocmb";

    // 模拟的存储上次请求的token
    private static readonly TokenData LastToken = new TokenData
    {
        AccessToken = "MbcTaUADPrJ9fdgsNLFjjcrdDM4j",
        ExpiresIn = 86733
    };

    // 业务逻辑处理函数
    public TokenResponse GetLastToken(string appkey, string appsecret)
    {
        // 验证appkey和appsecret
        if (appkey != ValidAppKey || appsecret != ValidAppSecret)
        {
            return new TokenResponse
            {
                ErrorTrace = "Invalid appkey or appsecret",
                ErrorCode = 401,
                Prompt = "Invalid parameters",
                Success = false
            };
        }

        // 查询上次请求的token
        if (LastToken == null || LastToken.ExpiresIn <= 0)
        {
            return new TokenResponse
            {
                ErrorTrace = "Token not found or expired",
                ErrorCode = 404,
                Prompt = "Token not found or expired",
                Success = false
            };
        }

        // 返回成功响应
        return new TokenResponse
        {
            ErrorTrace = null,
            ErrorCode = null,
            Prompt = null,
            Success = true,
            Data = LastToken
        };
    }
}
